<?php

function model_news($bdd) {

    $results = $bdd->query('SELECT * FROM `news`');

    return $results;
}

function count_news($bdd) {
    $req = $bdd->query('SELECT id_new FROM news');
    $count = $req->rowCount();
    return $count;
}

function model_update_news($bdd, $new_name, $new_description, $new_id, $type_img) { // premier enregistrement
    if ($type_img != 3) {
        $bdd->query("UPDATE news
            SET  new_description      = '$new_description',
                new_name ='$new_name',
	        img_type      = '$type_img'
           WHERE id_new = $new_id ");
    } else {
        $bdd->query("UPDATE news
            SET  new_description = '$new_description',
                                new_name ='$new_name'

           WHERE id_new = '$new_id' ");
    }
}

function model_update_Allnews($bdd, $new_name, $new_description, $i, $type_img) {
    if ($type_img != 3) {
        $bdd->query("UPDATE news
            SET  new_description      = '$new_description', 
                new_name ='$new_name',
	          img_type      = '$type_img'
           WHERE id_new = '$i' ");
    } else {
        $bdd->query("UPDATE news
            SET  new_description = '$new_description',
                new_name ='$new_name'
           WHERE id_new = '$i' ");
    }
}

function delete_news($bdd, $new_id) {
    $bdd->query("DELETE 
            FROM news
	    WHERE id_new = '$new_id'");
}

?>
